package cn.gson.crmdemo.controller.product;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.Emp;
import cn.gson.crmdemo.model.pojo.Purchase;
import cn.gson.crmdemo.model.service.CaigouService;
import cn.gson.crmdemo.model.vo.ProcurementDetailsVo;
import cn.gson.crmdemo.model.vo.RoleEmpVo;


@Controller
public class Caigou {
	//查询所有
	@Autowired
	CaigouService caigou;

	@RequestMapping("caigou")
	@ResponseBody
	public Map<String,Object>caigou(Integer pageNum,Integer pasgeSize,String purchaseNo){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray list=caigou.selectPurchase(purchaseNo);
		//创建Map集合
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("list",list);
		map.put("total",page.getTotal());
		return map;
}

	//模糊查询
	@RequestMapping("mhcx")
	@ResponseBody
	public JSONArray mhcx(String no) {
		return caigou.selectmhcx("%"+no+"%");
	}
	
	//新增
	@RequestMapping("add")
	public String add(@RequestBody List<ProcurementDetailsVo> cgmx,HttpServletRequest request) {
		Emp emp = (Emp) request.getSession().getAttribute("emp");
		caigou.addcgd(cgmx,emp.getEmpName());
		return "redirect:caigou?pageNum=1&pasgeSize=7&purchaseNo=";	
	}
	
	//修改
	@RequestMapping("xg")
	public String xiugai(Purchase id) {		
		caigou.xg(id);
		return "redirect:caigou?pageNum=1&pasgeSize=2 ";
	}
	

}
